//
//  StatusOriginalFrame.m
//  CC
//
//  Created by Calvin on 5/18/15.
//  Copyright (c) 2015 Calvin. All rights reserved.
//

#import "StatusOriginalFrame.h"
#import "StatusModel.h"
#import "UserModel.h"

@implementation StatusOriginalFrame
-(void)setStatus:(StatusModel *)status
{
    _status = status;
    
    //Calculate icon frame
    CGFloat iconX = CellStatusInset;
    CGFloat iconY = CellStatusInset;
    CGFloat iconW = 35;
    CGFloat iconH = 35;
    self.iconFrame = CGRectMake(iconX, iconY, iconW, iconH);
    
    //Calculate nickName frame
    CGFloat nameX = CGRectGetMaxX(self.iconFrame) + CellStatusInset;
    CGFloat nameY = iconY;
//    CGSize nameSize = [status.user.name sizeWithFont:StatusOrginalNameFont];
     CGSize nameSize = [status.created_at sizeWithAttributes:[NSDictionary dictionaryWithObjectsAndKeys:StatusOrginalNameFont,StatusOrginalNameFont.fontName,nil]];
    self.nameFrame = (CGRect){{nameX,nameY},nameSize};
    
    //Calculate time frame
    CGFloat timeX = nameX;
    CGFloat timeY = CGRectGetMaxY(self.nameFrame) + CellStatusInset*0.5;
//    CGSize timeSize = [status.created_at sizeWithFont:StatusOrginalTimeFont];
    CGSize timeSize = [status.created_at sizeWithAttributes:[NSDictionary dictionaryWithObjectsAndKeys:StatusOrginalTimeFont,StatusOrginalTimeFont.fontName,nil]];
    self.timeFrame = (CGRect){{timeX,timeY},timeSize};
    
    //Calculate source frame
    CGFloat sourceX = CGRectGetMaxX(self.textFrame) + CellStatusInset;
    CGFloat sourceY = timeY;
//    CGSize sourceSize = [status.source sizeWithFont:StatusOrginalSourceFont];
    CGSize sourceSize = [status.source sizeWithAttributes:[NSDictionary dictionaryWithObjectsAndKeys:StatusOrginalSourceFont,StatusOrginalSourceFont.fontName,nil]];
    self.sourceFrame = (CGRect){{sourceX,sourceY},sourceSize};
    
    //Calculate test size
    CGFloat textX = iconX;
    CGFloat textY = CGRectGetMaxY(self.iconFrame) + CellStatusInset;
    CGFloat screenW = ScreenW;
    CGFloat padding = CellStatusInset *2;
    CGFloat maxW = screenW - padding;
    CGSize maxSize=CGSizeMake(maxW, MAXFLOAT);
//    CGSize textSize = [status.text sizeWithAttributes:[NSDictionary dictionaryWithObjectsAndKeys:StatusOrginalTextFont,StatusOrginalTextFont.fontName,nil]];
    CGSize textSize=[status.text sizeWithFont:StatusOrginalTextFont constrainedToSize:maxSize];
    self.textFrame=(CGRect){{textX,textY},textSize};
    
    if (status.user.isVip)
    {
        CGFloat vipX=CGRectGetMaxX(self.nameFrame) + CellStatusInset;
        CGFloat vipY=nameY;
        CGFloat vipH=nameSize.height;
        CGFloat vipW=vipH;
        self.vipViewFrame=CGRectMake(vipX, vipY, vipW, vipH);
    }
    
    //Calculate self frame
    CGFloat x=0;
    CGFloat y=0;
    CGFloat w=ScreenW;
    CGFloat h=CGRectGetMaxY(self.textFrame)+CellStatusInset;
    self.frame=CGRectMake(x, y, w, h);
}
@end
